tinymce.PluginManager.add("indent2em", function (editor, url) {
  var pluginName = "首行缩进";
  var global$1 = tinymce.util.Tools.resolve("tinymce.util.Tools");
  var indent2em_val = editor.getParam("indent2em_val", "2em");
  var doAct = function () {
    var dom = editor.dom;
    var blocks = editor.selection.getSelectedBlocks();
    var act = "";
    global$1.each(blocks, function (block) {
      if (act == "") {
        act =
          dom.getStyle(block, "text-indent") == indent2em_val
            ? "remove"
            : "add";
      }
      if (act == "add") {
        dom.setStyle(block, "text-indent", indent2em_val);
      } else {
        var style = dom.getAttrib(block, "style");
        var reg = new RegExp("text-indent:[\\s]*" + indent2em_val + ";", "ig");
        style = style.replace(reg, "");
        dom.setAttrib(block, "style", style);
      }
    });
  };

  editor.ui.registry.getAll().icons.indent2em ||
    editor.ui.registry.addIcon(
      "indent2em",
      '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24" fill="none"><rect x="0" y="0" width="0" height="0" fill="rgba(249, 249, 249, 1)" /><defs><rect id="path_0" x="0" y="0" width="24" height="24" /></defs><g opacity="1" transform="translate(0 0)  rotate(0 12 12)"><mask id="bg-mask-0" fill="white"><use xlink:href="#path_0"></use></mask><g mask="url(#bg-mask-0)" ><g opacity="1" transform="translate(4 5)  rotate(0 8 7)"><g opacity="1" transform="translate(0 0)  rotate(0 8 7)"><path id="路径 1" fill-rule="evenodd" style="fill:#000000" transform="translate(2 8)  rotate(0 7 1)" opacity="1" d="M0,1C0,1.55 0.45,2 1,2L13,2C13.55,2 14,1.55 14,1C14,0.45 13.55,0 13,0L1,0C0.45,0 0,0.45 0,1Z " /><path id="路径 2" fill-rule="evenodd" style="fill:#000000" transform="translate(6.9999999993919975 0.00010626990265194536)  rotate(0 4.5 1)" opacity="1" d="M0,1C0,1.55 0.45,2 1,2L8,2C8.55,2 9,1.55 9,1C9,0.45 8.55,0 8,0L1,0C0.45,0 0,0.45 0,1Z " /><path id="路径 3" fill-rule="evenodd" style="fill:#000000" transform="translate(6.9999999993919975 4.000106269902652)  rotate(0 4.5 1)" opacity="1" d="M0,1C0,1.55 0.45,2 1,2L8,2C8.55,2 9,1.55 9,1C9,0.45 8.55,0 8,0L1,0C0.45,0 0,0.45 0,1Z " /><path id="路径 4" fill-rule="evenodd" style="fill:#000000" transform="translate(2 12)  rotate(0 7 1)" opacity="1" d="M0,1C0,1.55 0.45,2 1,2L13,2C13.55,2 14,1.55 14,1C14,0.45 13.55,0 13,0L1,0C0.45,0 0,0.45 0,1Z " /><path id="路径 5" fill-rule="evenodd" style="fill:#000000" transform="translate(0 0)  rotate(0 2.5000531359459988 3.00010628475294)" opacity="1" d="M1.55,5.83L4.55,3.83C5.15,3.44 5.15,2.56 4.55,2.17L1.55,0.17C1.1,-0.14 0.47,-0.01 0.17,0.45C-0.14,0.9 -0.01,1.53 0.45,1.83L2.2,3L0.45,4.17C-0.01,4.47 -0.14,5.1 0.17,5.55C0.47,6.01 1.1,6.14 1.55,5.83Z " /></g></g></g></g></svg>'
    );

  var stateSelectorAdapter = function (editor, selector) {
    return function (buttonApi) {
      return editor.selection.selectorChangedWithUnbind(
        selector.join(","),
        buttonApi.setActive
      ).unbind;
    };
  };

  editor.ui.registry.addToggleButton("indent2em", {
    icon: "indent2em",
    tooltip: pluginName,
    onAction: function () {
      doAct();
    },
    onSetup: stateSelectorAdapter(editor, [
      '*[style*="text-indent"]',
      '*[data-mce-style*="text-indent"]',
    ]),
  });

  editor.ui.registry.addMenuItem("indent2em", {
    text: pluginName,
    onAction: function () {
      doAct();
    },
  });

  editor.addCommand("indent2em", doAct);

  return {
    getMetadata: function () {
      return {
        name: pluginName,
        url: "http://tinymce.ax-z.cn/more-plugins/indent2em.php",
      };
    },
  };
});
